package hadoop.reduceJoin;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;

import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class TableDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setJarByClass(TableDriver.class);
        job.setMapperClass(TableMapper.class);
        job.setReducerClass(TableReducer.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(TableBean.class);
        job.setOutputKeyClass(TableBean.class);
        job.setOutputValueClass(NullWritable.class);

        FileSystem fs = FileSystem.get(conf);
        Path outputpath = new Path("D:\\apache-maven-3.6.3\\workOutput\\hadoop\\reduceJoin\\output");
        if (fs.exists(outputpath)) {
            fs.delete(outputpath, true);
        }
        FileInputFormat.setInputPaths(job, new Path("D:\\apache-maven-3.6.3\\mavenRepository\\mapReduce\\dataSet\\inputtable"));
        FileOutputFormat.setOutputPath(job, outputpath);

        boolean isDone = job.waitForCompletion(true);
        System.exit(isDone ? 0 : 1);

    }
}
